<template>
	<div class="mainWindow">
		<div>
			<router-view></router-view>
		</div>
	</div>
</template>

<script>
import AppService from './AppService.ts'

const tg = window.Telegram.WebApp

tg.expand()
export default {
	data() {
		return {}
	},
	methods: {
		logOut() {
			window.localStorage.setItem('userRole', null)
			this.$router.push('/login')
		},
	},
	created() {
		AppService.checkAuth(tg.initDataUnsafe.user.id)
			.then(res => {
				if (res === null) {
					this.logOut()
				} else {
					if (res === 'user') {
						window.localStorage.setItem('userRole', 'user')
					} else {
						window.localStorage.setItem('userRole', 'trader')
					}
				}
			})
			.catch(error => alert(error))
	},
}
</script>

<style>
* {
	margin: 0;
	padding: 0;
}

html,
body {
	width: 100%;
	height: 100%;
	background-color: var(--tg-theme-secondary-bg-color);
	box-sizing: border-box;
}

#app {
	width: 100%;
	height: 100%;
}

.mainWindow {
	width: 100%;
	height: 100%;
}

.loginContent {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}
</style>
